/**
 * Copyright (C) 2012 Daniel Gee.
 * See LICENSE.txt for more details.
 */
package com.rl.gui;

import java.awt.Color;
import java.io.Serializable;

/**
 * Defines the appearance of something within the dungeon, such as an Item or a Creature. Because an
 * Appearance can't be altered, it's entirely reasonable for several things to share the same
 * Appearance instance if they look alike.
 * 
 * @author Daniel Gee
 */
public class Appearance implements Serializable
{
	/**
	 * eclipse generated uID, 2013-04-15
	 */
	private static final long serialVersionUID = -2586541404795883436L;

	/**
	 * The shape of the thing.
	 */
	public final char character;

	/**
	 * The HTML color code of the thing.
	 */
	public final Color color;

	/**
	 * Creates a new Appearance instance. Appearances are immutable, so you can share the same one
	 * over and over. Only make new ones for things that are actually visually distinct.
	 * 
	 * @param character
	 *            the shape of this appearance.
	 * @param color
	 *            the color of this appearance.
	 */
	public Appearance(char character, Color color)
	{
		super();
		this.character = character;
		this.color = color;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (this == obj)
		{
			return true;
		}
		if (obj == null)
		{
			return false;
		}
		if (this.getClass() != obj.getClass())
		{
			return false;
		}
		Appearance other = (Appearance) obj;
		if (this.character != other.character)
		{
			return false;
		}
		if (this.color == null)
		{
			if (other.color != null)
			{
				return false;
			}
		}
		else if (!this.color.equals(other.color))
		{
			return false;
		}
		return true;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + this.character;
		result = prime * result + ((this.color == null) ? 0 : this.color.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return "Appearance('" + this.character + "', " + this.color + ")";
	}
}
